using UnityEngine;
using System.Collections;

public class CIntersectMgr
{
    Sprite m_TouchEffect;
    // Use this for initialization
	public void StartGame () {
        GameObject SpriteEffectObject = GameObject.Find("TouchEffect");
        if (null != SpriteEffectObject)
        {
			Debug.Log("Find TouchEffect Object");
            m_TouchEffect = SpriteEffectObject.GetComponent<Sprite>();
            SpriteEffectObject.active = false;
        }
	}
	
	// Update is called once per frame
    public void UpdatePlaying()
    {
        if (RuntimePlatform.Android == Application.platform ||
            RuntimePlatform.IPhonePlayer == Application.platform)
        {
            for (int nTouchIndex = 0; nTouchIndex < Input.touchCount; nTouchIndex++)
            {
                if (TouchPhase.Began == Input.touches[nTouchIndex].phase)
                {
                    Vector3 vPosition = new Vector3(Input.touches[nTouchIndex].position.x, Input.touches[nTouchIndex].position.y);
                    // Debug.Log(nTouchIndex.ToString() + vPosition.ToString());
                    TouchTarget(vPosition);
                }
            }
        }
        else
        {
            if (true == Input.GetMouseButtonDown(0))
            {
                TouchTarget(Input.mousePosition);
            }
        }
	}

    private void TouchTarget( Vector3 vPosition )
    {
        RaycastHit rayhit;
        Ray ray = Camera.main.ScreenPointToRay(vPosition);
        if (true == Physics.Raycast(ray, out rayhit) && rayhit.collider.tag == "TAG_TARGET")
        {
            Debug.Log(rayhit.point.ToString());
            GameObject CollidObject = rayhit.collider.gameObject;
            CTargetProperty TargetComponent = CollidObject.GetComponent<CTargetProperty>();
            TargetComponent.Touch();
			CGlobalMgr.Instance.EffectMgr.Touch( CEffectMgr.E_TYPE.TOUCH, rayhit.point);
        }
    }
}
